#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   App_ControlDTCSetting_0x85_test.py
@Time    :   2024/09/11 13:31:28
@Author  :   yangliang 
@Version :   1.0
@Contact :   yangliang@chengtech.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''

# here put the import lib
from pytest_assume.plugin import assume

import pytest
import time
# from sympy import assuming
from commDriver.TS_CAN import *
import allure
import sys
from collections.abc import Iterable

from sqlalchemy import false
sys.dont_write_bytecode = True

SID85_ControlDTCSetting = [([0x85, 0x02], [0xC5, 0x02]),
                           ([0x85, 0x01], [0xC5, 0x01])
                        ]

SID85_ControlDTCSetting_SuppressPosMsgBit = [([0x85, 0x82], []),
                                             ([0x85, 0x81], [])
                                            ]

controlDTCSetting_NRC_Phy = [([0x85], [0x7F, 0x85, 0x13]),
                             ([0x85, 0x02, 0x01], [0x7F, 0x85, 0x13]),
                             ([0x85, 0x01, 0xFF], [0x7F, 0x85, 0x13]),
                             ([0x85, 0x22, 0x13], [0x7F, 0x85, 0x12]),
                             ([0x85, 0x00], [0x7F, 0x85, 0x12]),
                             ([0x85, 0x03], [0x7F, 0x85, 0x12]),
                             ([0x85, 0x3F], [0x7F, 0x85, 0x12]),
                             ([0x85, 0x40], [0x7F, 0x85, 0x12]),
                             ([0x85, 0x5F], [0x7F, 0x85, 0x12]),
                             ([0x85, 0x60], [0x7F, 0x85, 0x12]),
                             ([0x85, 0x7E], [0x7F, 0x85, 0x12]),
                             ([0x85, 0x7F], [0x7F, 0x85, 0x12])
                            ]

controlDTCSetting_NRC13_Fun = [([0x85], [0x7F, 0x85, 0x13]),
                               ([0x85, 0x02, 0x01], [0x7F, 0x85, 0x13]),
                               ([0x85, 0x01, 0xFF], [0x7F, 0x85, 0x13])
                            ]

controlDTCSetting_NRC7F_Fun = [([0x85, 0x01], [0x7F, 0x85, 0x7F]),
                               ([0x85, 0x02], [0x7F, 0x85, 0x7F]),
                               ([0x85, 0x81], [0x7F, 0x85, 0x7F]),
                               ([0x85, 0x82], [0x7F, 0x85, 0x7F]),
                            ]

controlDTCSetting_No_Resp_Fun = [   ([0x85, 0x00], []),
                                    ([0x85, 0x03], []),
                                    ([0x85, 0x3F], []),
                                    ([0x85, 0x40], []),
                                    ([0x85, 0x5F], []),
                                    ([0x85, 0x60], []),
                                    ([0x85, 0x7E], []),
                                    ([0x85, 0x7F], []),
                                    ([0x85, 0x22, 0x13], [])
                                ]

controlDTCSetting_SuppressPosMsgBit_NRC_Phy = [ ([0x85, 0x82, 0x01], [0x7F, 0x85, 0x13]),
                                                ([0x85, 0x81, 0xFF], [0x7F, 0x85, 0x13]),
                                                ([0x85, 0x22, 0x13], [0x7F, 0x85, 0x12]),
                                                ([0x85, 0x90], [0x7F, 0x85, 0x12]),
                                                ([0x85, 0x83], [0x7F, 0x85, 0x12]),
                                                ([0x85, 0x8F], [0x7F, 0x85, 0x12]),
                                                ([0x85, 0x9B], [0x7F, 0x85, 0x12]),
                                                ([0x85, 0xBF], [0x7F, 0x85, 0x12]),
                                                ([0x85, 0xB0], [0x7F, 0x85, 0x12]),
                                                ([0x85, 0x8E], [0x7F, 0x85, 0x12]),
                                                ([0x85, 0x87], [0x7F, 0x85, 0x12])
                                            ]

controlDTCSetting_SuppressPosMsgBit_NRC13_Fun = [([0x85, 0x82, 0x01], [0x7F, 0x85, 0x13]),
                                                 ([0x85, 0x81, 0xFF], [0x7F, 0x85, 0x13])
                                                ]

controlDTCSetting_SuppressPosMsgBit_No_Resp_Fun = [([0x85, 0x80], []),
                                                   ([0x85, 0x83], []),
                                                   ([0x85, 0x8A], []),
                                                   ([0x85, 0x90], []),
                                                   ([0x85, 0x91], []),
                                                   ([0x85, 0x83], []),
                                                   ([0x85, 0x8E], []),
                                                   ([0x85, 0x8F], []),
                                                   ([0x85, 0x87, 0x13], [])
                                                ]

controlDTCSetting_SuppressPosMsgBit_NoResp_default_Fun = [([0x85, 0x02], []),
                                                          ([0x85, 0x01], []),
                                                          ([0x85, 0x81], []),
                                                          ([0x85, 0x82], [])
                                                        ]


class Test_ControlDTCSetting_Phy(object):

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in SID85_ControlDTCSetting]
    @pytest.mark.smoke
    @allure.severity('normal')
    @allure.story('Control DTC Setting Test')
    @allure.description('Test positive response of 0x85 with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', SID85_ControlDTCSetting, ids=ids)
    def test_ControlDTCSetting_Extended_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep)
    

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in controlDTCSetting_NRC_Phy]
    @allure.severity('minor')
    @allure.description('Test negative response code of 0x85 when suppressPosMsgBit is enabled with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', controlDTCSetting_NRC_Phy, ids=ids)
    def test_ControlDTCSetting_NRC_Extended_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep)

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in controlDTCSetting_NRC7F_Fun]
    @allure.severity('minor')
    @allure.description('Test NRC7F of 0x85 with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', controlDTCSetting_NRC7F_Fun, ids=ids)
    def test_ControlDTCSetting_NRC7F_Default_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep)

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in controlDTCSetting_NRC7F_Fun]
    @allure.severity('minor')
    @allure.description('Test NRC7F of 0x85 with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', controlDTCSetting_NRC7F_Fun, ids=ids)
    def test_ControlDTCSetting_NRC7F_Programming_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep)

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in SID85_ControlDTCSetting_SuppressPosMsgBit]
    @allure.severity('normal')
    @allure.description('Test positive response of 0x85  when suppressPosMsgBit is enabled with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', SID85_ControlDTCSetting_SuppressPosMsgBit, ids=ids)
    def test_ControlDTCSetting_SuppressPosMsgBit_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep)

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in controlDTCSetting_SuppressPosMsgBit_NRC_Phy]
    @allure.severity('minor')
    @allure.description('Test negative response code of 0x85 when suppressPosMsgBit is enabled with physical addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', controlDTCSetting_SuppressPosMsgBit_NRC_Phy, ids=ids)
    def test_ControlDTCSetting_SuppressPosMsgBit_NRC_Phy(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep)

    @allure.severity('critical')
    @allure.description('Test dtc code output or not when setting 0x85 on off')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    def test_ControlDTCSetting_onoff_Extended_Phy(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '3E00', '7E00', 3, iStep)

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep)

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98,0x7A,0x17,0x09 found False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 02', 'C5 02', 0, iStep)

        iStep = Driver['CAN'].SetVolt(Driver, 17, 1, iStep)
        
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98,0x7A,0x17,0x09 found False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1
        
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 01', 'C5 01', 0, iStep)

        iStep = Driver['CAN'].SetVolt(Driver, 17, 1, iStep)
    
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:with 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09])
            if a != True:
                logging.error(f'correct response:[True], actual response:[{a}]')
            with assume:
                assert a == True
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep)

    @allure.severity('critical')
    @allure.description('Test dtc code output or not when setting 0x85 on off')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    def test_ControlDTCSetting_onoff_change_session_Extended_Phy(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '3E00', '7E00', 3, iStep)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep)

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98, 0x7A, 0x17, 0x09 found False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 02', 'C5 02', 0, iStep)

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 01', '50 01', 0, iStep)
        iStep = Driver['CAN'].SetVolt(Driver, 17, 1, iStep)
        
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != True:
                logging.error(f'correct response:[0x5C,0x03,0x17,0x0B False], actual response:[{a}]')
            with assume:
                assert a == True
            iStep += 1
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

    @allure.severity('critical')
    @allure.description('Test dtc code output or not when setting 0x85 on off')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    def test_ControlDTCSetting_onoff_S3timeout_Extended_Phy(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '3E00', '7E00', 3, iStep)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep)

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98, 0x7A, 0x17, 0x09 found False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 02', 'C5 02', 0, iStep)
        time.sleep(5)
        iStep = Driver['CAN'].SetVolt(Driver, 17, 1, iStep)

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != True:
                logging.error(f'correct response:[0x98, 0x7A, 0x17, 0x09 False], actual response:[{a}]')
            with assume:
                assert a == True
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

    @allure.severity('critical')
    @allure.description('Test dtc code output or not when setting 0x85 SuppressPosMsgBit on off')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    def test_ControlDTCSetting_onoff_SuppressPosMsgBit_Phy(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '3E00', '7E00', 3, iStep)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep)

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x16,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x16, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98, 0x7A, 0x16, 0x09 False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1
        
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 82', '', 0, iStep)
        
        iStep = Driver['CAN'].SetVolt(Driver, 8, 1, iStep)
        
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x16,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x16, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98, 0x7A, 0x16, 0x09 False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 81', '', 0, iStep)
        iStep = Driver['CAN'].SetVolt(Driver, 8, 1, iStep)
        
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:with 0x98,0x7A,0x16,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x16, 0x09])
            if a != True:
                logging.error(f'correct response:[0x98, 0x7A, 0x16, 0x09 True], actual response:[{a}]')
            with assume:
                assert a == True
            iStep += 1
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep)

class Test_ControlDTCSetting_Fun(object):

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in SID85_ControlDTCSetting]
    @allure.severity('normal')
    @allure.story('Control DTC Setting Test with function ')
    @allure.description('Test positive response of 0x85 with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', SID85_ControlDTCSetting, ids=ids)
    def test_ControlDTCSetting_Extended_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun')
        

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in SID85_ControlDTCSetting_SuppressPosMsgBit]
    @allure.severity('normal')
    @allure.description('Test positive response of 0x85  when suppressPosMsgBit is enabled with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', SID85_ControlDTCSetting_SuppressPosMsgBit, ids=ids)
    def test_ControlDTCSetting_SuppressPosMsgBit_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun')

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in controlDTCSetting_SuppressPosMsgBit_NRC13_Fun]
    @allure.severity('minor')
    @allure.description('Test NRC13 of 0x85 when suppressPosMsgBit is enabled with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', controlDTCSetting_SuppressPosMsgBit_NRC13_Fun, ids=ids)
    def test_ControlDTCSetting_SuppressPosMsgBit_NRC13_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun')

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in controlDTCSetting_SuppressPosMsgBit_No_Resp_Fun]
    @allure.severity('minor')
    @allure.description('Test no response of 0x85 when suppressPosMsgBit is enabled with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', controlDTCSetting_SuppressPosMsgBit_No_Resp_Fun, ids=ids)
    def test_ControlDTCSetting_SuppressPosMsgBit_No_Resp_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 3, iStep, False, 'UDSFun')

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in controlDTCSetting_SuppressPosMsgBit_NoResp_default_Fun]
    @allure.severity('minor')
    @allure.description('Test no response of 0x85 when suppressPosMsgBit is enabled with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', controlDTCSetting_SuppressPosMsgBit_NoResp_default_Fun, ids=ids)
    def test_ControlDTCSetting_SuppressPosMsgBit_NoResp_Default_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 1, iStep, False, 'UDSFun')

    
    @allure.severity('critical')
    @allure.description('Test dtc code output or not when setting 0x85 on off with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    def test_ControlDTCSetting_onoff_Extended_Fun(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '3E00', '7E00', 3, iStep, False, 'UDSFun')

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False, 'UDSFun')

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98,0x7A,0x17,0x09 found False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 02', 'C5 02', 0, iStep, False, 'UDSFun')

        iStep = Driver['CAN'].SetVolt(Driver, 17, 1, iStep)
        
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98,0x7A,0x17,0x09 found False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1
        
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 01', 'C5 01', 0, iStep, False, 'UDSFun')

        iStep = Driver['CAN'].SetVolt(Driver, 17, 1, iStep)
    
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:with 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09])
            if a != True:
                logging.error(f'correct response:[True], actual response:[{a}]')
            with assume:
                assert a == True
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False, 'UDSFun')

    @allure.severity('critical')
    @allure.description('Test dtc code output or not when setting 0x85 on off with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    def test_ControlDTCSetting_onoff_change_session_Extended_Fun(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '3E00', '7E00', 3, iStep, False, 'UDSFun')
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False, 'UDSFun')

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98, 0x7A, 0x17, 0x09 found False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 02', 'C5 02', 0, iStep, False, 'UDSFun')

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '10 01', '50 01', 0, iStep, False, 'UDSFun')
        iStep = Driver['CAN'].SetVolt(Driver, 17, 1, iStep)
        
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != True:
                logging.error(f'correct response:[0x5C,0x03,0x17,0x0B False], actual response:[{a}]')
            with assume:
                assert a == True
            iStep += 1
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

    @allure.severity('critical')
    @allure.description('Test dtc code output or not when setting 0x85 on off with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    def test_ControlDTCSetting_onoff_S3timeout_Extended_Fun(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '3E00', '7E00', 3, iStep, False, 'UDSFun')
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False, 'UDSFun')

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98, 0x7A, 0x17, 0x09 found False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 02', 'C5 02', 0, iStep, False, 'UDSFun')
        time.sleep(5)
        iStep = Driver['CAN'].SetVolt(Driver, 17, 1, iStep)

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x17,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x17, 0x09], timeout=1)
            if a != True:
                logging.error(f'correct response:[0x98, 0x7A, 0x17, 0x09 False], actual response:[{a}]')
            with assume:
                assert a == True
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

    @allure.severity('critical')
    @allure.description('Test dtc code output or not when setting 0x85 SuppressPosMsgBit on off with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    def test_ControlDTCSetting_onoff_SuppressPosMsgBit_Fun(self, action, Driver):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '3E00', '7E00', 3, iStep, False, 'UDSFun')
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False, 'UDSFun')

        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x16,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x16, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98, 0x7A, 0x16, 0x09 False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1
        
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 82', '', 0, iStep, False, 'UDSFun')
        
        iStep = Driver['CAN'].SetVolt(Driver, 8, 1, iStep)
        
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:no 0x98,0x7A,0x16,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x16, 0x09], timeout=1)
            if a != False:
                logging.error(f'correct response:[0x98, 0x7A, 0x16, 0x09 False], actual response:[{a}]')
            with assume:
                assert a == False
            iStep += 1

        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '85 81', '', 0, iStep, False, 'UDSFun')

        iStep = Driver['CAN'].SetVolt(Driver, 8, 1, iStep)
        
        with allure.step(f'Step{iStep}:Request:0x19,0x02,0x09, # Response:with 0x98,0x7A,0x16,0x09'):
            a, b, c = Driver['UDS'].search_DTC([0x19, 0x02, 0x09], [0x98, 0x7A, 0x16, 0x09])
            if a != True:
                logging.error(f'correct response:[0x98, 0x7A, 0x16, 0x09 True], actual response:[{a}]')
            with assume:
                assert a == True
            iStep += 1
        iStep = Driver['CAN'].SetVolt(Driver, 12, 1, iStep)

        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, '14 FF FF FF', '54', 0, iStep, False, 'UDSFun')

    
    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in controlDTCSetting_NRC7F_Fun]
    @allure.severity('minor')
    @allure.description('Test NRC7F of 0x85 with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', controlDTCSetting_NRC7F_Fun, ids=ids)
    def test_ControlDTCSetting_NRC7F_Default_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 1, iStep, False, 'UDSFun')

    ids = ['Request:{0}'.format(binascii.b2a_hex(bytearray(req), ' '))for req, resp in controlDTCSetting_NRC7F_Fun]
    @allure.severity('minor')
    @allure.description('Test NRC7F of 0x85 with functional addressing')
    @allure.testcase('https://chengtech.pingcode.com/testhub/libraries/6306e0482ce6d84a055b6e90/cases')
    @pytest.mark.parametrize('req,resp', controlDTCSetting_NRC7F_Fun, ids=ids)
    def test_ControlDTCSetting_NRC7F_Programming_Fun(self, action, Driver, req, resp):
        iStep = 1
        iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, '', 2, iStep, False, 'UDSFun')
